package cn.demo.common.mybatisFlex;

import cn.demo.common.core.domain.BaseEntity;
import cn.demo.common.utils.ObjUtils;
import cn.demo.common.utils.SecurityUtils;
import com.mybatisflex.annotation.InsertListener;

public class MyInsertListener implements InsertListener {

    @Override
    public void onInsert(Object object) {
        if (ObjUtils.isNotNull(object) && object instanceof BaseEntity entity){
            entity.setCreateBy(ObjUtils.defaultIfNull(SecurityUtils.getUsername(),SecurityUtils.getUserId()));
        }
    }
}